library(flextable)
library(DiagrammeR)

library(lavaan)

library(tidyverse)

At this point, I will construct an overall mediation model.

Diagram

Let’s take a look at the boxes-and-arrows.

grViz("

digraph mediation {
  
  graph [overlap = true,
         rankdir = LR,
         bgcolor = '#222222']
  
  node [shape = box,
        color = wheat,
        fontcolor = wheat]
        
  edge [color = wheat,
        fontcolor = wheat]
  
  disclosure->'affective trust' [label = <a<SUB>aff</SUB>>]
  disclosure->liking [label = 'c&prime;']
  disclosure->'cognitive trust' [label = <a<SUB>cog</SUB>>]
  'affective trust'->liking [label = <b<SUB>aff</SUB>>]
  'cognitive trust'->liking [label = <b<SUB>cog</SUB>>]
  
}
")

Statistical Models

Now, I’ll build the actual data model. My understanding is that I can follow the classic procedure, but control for cognitive trust when testing affective trust—and vice versa.

data <- readRDS(file.path("..", "data", "hq-data.rds"))
formatAsTable <- readRDS("format.rds")

Mediation by Affective Trust

model.aff <- "# measurement model
              aff =~ aff1 + aff2 + aff3 + aff4
              lik =~ lik1 + lik2 + lik3.r + lik4.r

              # structural model
              aff ~ affa*disclose
              lik ~ affb*aff
              lik ~ cprime*disclose
              ind_fx := affa*affb
              tot_fx := affa*affb + cprime"

fit.aff <- model.aff %>%
  sem(data)

fit.aff %>%
  parameterEstimates %>%
  filter(op %in% c("~", ":=")) %>%
  formatAsTable

\(c\prime\) goes to zero…looks like full mediation!

Mediation by Cognitive Trust

model.cog <- "# measurement model
              cog =~ cog1 + cog2 + cog3
              lik =~ lik1 + lik2 + lik3.r + lik4.r

              # structural model
              cog ~ coga*disclose
              lik ~ cogb*cog
              lik ~ cprime*disclose
              ind_fx := coga*cogb
              tot_fx := coga*cogb + cprime"

fit.cog <- model.cog %>%
  sem(data)

fit.cog %>%
  parameterEstimates %>%
  filter(op %in% c("~", ":=")) %>%
  formatAsTable

\(c\prime\) doesn’t go to zero, so we can’t say we have full mediation. But \(a_{cog}\) and \(b_{cog}\) are significant, so I think that means partial mediation.

Mediation by Both

model.tru <- "# measurement model
              aff =~ aff1 + aff2 + aff3 + aff4
              cog =~ cog1 + cog2 + cog3
              lik =~ lik1 + lik2 + lik3.r + lik4.r

              # structural model
              aff ~ affa*disclose
              cog ~ coga*disclose
              lik ~ affb*aff + cogb*cog
              lik ~ cprime*disclose
              ind_fx := affa*affb + coga*cogb
              tot_fx := affa*affb + coga*cogb + cprime"

fit.tru <- model.tru %>%
  sem(data)

fit.tru %>%
  parameterEstimates %>%
  filter(op %in% c("~", ":=")) %>%
  formatAsTable

That’s interesting! Trust doesn’t fully mediate the effect of disclosure on liking—it inconsistently mediates it. That is, disclosure has a significantly negative effect on liking when controlling for trust.

I’m not sure what would explain that. Maybe something like my hypothesis (that disclosure calls attention to negative aspects of ADHD) is true, but cognitive trust was the wrong construct to use. Or it could be that disclosure makes someone trustworthy, but otherwise makes them look bad (annoying, poor social skills, oversharing, that kind of thing). There’s no way to know for sure without more studies.

Also, as predicted, affective trust is a stronger mediator than cognitive trust.


Output document:

options(knitr.duplicate.label = "allow")
rmarkdown::render("mediation.Rmd",
                  output_dir = file.path("..", "github", "thesis"))